//
//  NewInstallCell.m
//  CarLife
//
//  Created by yu on 2018/2/9.
//  Copyright © 2018年 jpas. All rights reserved.
//

#import "NewInstallCell.h"
#import "WorkorderModel.h"
#import "EquipModel.h"

@implementation NewInstallCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (IBAction)photoAction:(UIButton *)btn
{
    if (self.photoActionBlock) {
        self.photoActionBlock(btn.tag-1);
    }
}

- (void)setEqModel:(EquipModel *)eqModel
{
    _eqModel = eqModel;
    
    self.eqNumLabel.text = eqModel.eqNo;
    self.eqModelLabel.text = eqModel.eqType;
    
    if (eqModel.isFinish) {
        self.photoBtn.userInteractionEnabled = NO;
        [self.photoBtn setTitle:@"已拍完" forState:UIControlStateNormal];
        [self.photoBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.photoBtn setImage:IMAGE_NAMED(@"") forState:UIControlStateNormal];
    } else {
        self.photoBtn.userInteractionEnabled = YES;
        [self.photoBtn setImage:IMAGE_NAMED(@"photo") forState:UIControlStateNormal];
        [self.photoBtn setTitle:@"" forState:UIControlStateNormal];
    }
}


- (void)setWoModel:(WorkorderModel *)woModel
{
    _woModel = woModel;
    self.siteContactLabel.text = NSStringFormat(@"现场联系人名字：%@",woModel.siteContact);
    self.siteMobileLabel.text = NSStringFormat(@"现场联系人电话：%@",woModel.siteContactTel);
    self.appointmentTimeLabel.text = NSStringFormat(@"预约安装时间：%@",woModel.preInstallTime);
    self.installSiteLabel.text = NSStringFormat(@"安装地点：%@",woModel.installSite);
    self.senderLabel.text = NSStringFormat(@"派单负责人姓名：%@",woModel.charger);
    self.senderMobileLabel.text = NSStringFormat(@"派单负责人电话：%@",woModel.chargerTel);
    self.orderNoLabel.text = NSStringFormat(@"工单编号：%@",woModel.workOrderNo);
    self.orderTypeLabel.text = NSStringFormat(@"工单类型：%@",[self workorderType]);
    self.orderOrganLabel.text = NSStringFormat(@"下单机构：%@",woModel.creater);
    self.agencyLabel.text = NSStringFormat(@"车辆所属经销商：%@",woModel.createrDept);
    self.motorcycleTypeLabel.text = NSStringFormat(@"车型：%@",woModel.carType);
    self.vinLabel.text = NSStringFormat(@"车架号：%@",woModel.vin);
    self.plateLabel.text = NSStringFormat(@"车牌号：%@",woModel.carNo);
    self.orderNoteLabel.text = NSStringFormat(@"备注：%@",woModel.workComments);
}

+ (instancetype)initTableViewCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    NSString *identifier;
    NSInteger index = 0;
    switch (indexPath.section) {
        case 0:
            identifier = @"NewInstallCell0";
            index = 0;
            break;
        case 1:
            identifier = @"NewInstallCell1";
            index = 1;
            break;
        default:
            break;
    }
    
    NewInstallCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"NewInstallCell" owner:self options:nil] objectAtIndex:index];
    }
    return cell;
}

- (NSString *)workorderType {
    NSString *wordOrderType = NSStringFormat(@"%@",self.woModel.wordOrderType);
    if ([wordOrderType isEqualToString:@"0"]) {
        wordOrderType = @"新装";
    } else if ([wordOrderType isEqualToString:@"1"]) {
        wordOrderType = @"维护";
    } else if ([wordOrderType isEqualToString:@"2"]) {
        wordOrderType = @"拆机";
    } else if ([wordOrderType isEqualToString:@"3"]) {
        wordOrderType = @"移机";
    } else if ([wordOrderType isEqualToString:@"4"]) {
        wordOrderType = @"家访";
    }
    return wordOrderType;
}

//- (NSString *)homeVisType {
//    NSString *homeVisitsType = NSStringFormat(@"%@",self.woModel.homeVisitsType);
//    if ([homeVisitsType isEqualToString:@"1"]) {
//        homeVisitsType = @"家庭拜访";
//    } else if ([homeVisitsType isEqualToString:@"2"]) {
//        homeVisitsType = @"员工公司拜访";
//    } else {
//        homeVisitsType = @"私营业主公司拜访";
//    }
//    return homeVisitsType;
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
